package com.jrx.anytxn.param.utils;

import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.param.enums.RightsEffectivePeriodInActivityEnum;

import java.util.Calendar;
import java.util.Date;

/**
 * ClassName ActivityUtils
 *
 * @author lujianyou
 * @version 1.0
 * @description 活动静态方法
 * @date 2021/12/25 15:22
 **/
public class ActivityUtils {

    /**
     * 获取活动下发权益的生效时间
     * @param rightsEffectivePeriod
     * @param rightsEffectiveDate
     * @param defaultEffectiveDate
     * @return
     */
    public static Date getEffectiveDateFrom(String rightsEffectivePeriod, Date rightsEffectiveDate,
        Date defaultEffectiveDate) {
        if (RightsEffectivePeriodInActivityEnum.FREE.getCode().equals(rightsEffectivePeriod)) {
            return rightsEffectiveDate;
        }
        if (RightsEffectivePeriodInActivityEnum.WEEKLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.parseDate(DateUtils.getDayOfWeek(Calendar.MONDAY), DateUtils.DATE_PATTERN);
        }
        if (RightsEffectivePeriodInActivityEnum.FRIDAY_TO_SUNDAY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.parseDate(DateUtils.getDayOfWeek(Calendar.FRIDAY), DateUtils.DATE_PATTERN);
        }
        if (RightsEffectivePeriodInActivityEnum.MONTHLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.getMonthStartTime(new Date());
        }
        if (RightsEffectivePeriodInActivityEnum.MONTHSLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.getMonthStartTime(new Date());
        }
        return defaultEffectiveDate;
    }

    /**
     *
     * @param rightsEffectivePeriod
     * @param rightsExpireDate
     * @param defaultEffectiveDate
     * @return
     */
    public static Date getExpireDateFrom(String rightsEffectivePeriod, Date rightsExpireDate,
        Date defaultEffectiveDate) {
        if (RightsEffectivePeriodInActivityEnum.FREE.getCode().equals(rightsEffectivePeriod)) {
            return rightsExpireDate;
        }
        if (RightsEffectivePeriodInActivityEnum.WEEKLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.parseDate(DateUtils.getDayOfWeek(Calendar.SUNDAY), DateUtils.DATE_PATTERN);
        }
        if (RightsEffectivePeriodInActivityEnum.FRIDAY_TO_SUNDAY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.parseDate(DateUtils.getDayOfWeek(Calendar.SUNDAY), DateUtils.DATE_PATTERN);
        }
        if (RightsEffectivePeriodInActivityEnum.MONTHLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.getMonthEndTime(new Date());
        }
        if (RightsEffectivePeriodInActivityEnum.MONTHSLY.getCode().equals(rightsEffectivePeriod)) {
            return DateUtils.getMonthEndTime(new Date());
        }
        return defaultEffectiveDate;
    }
}
